import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class demo1 {
    public static void main(String[] args) throws SQLException {
        //1.创建dataSource
        DataSource dataSource = new MysqlDataSource();
        ((MysqlDataSource) dataSource).setURL("jdbc:mysql://127.0.0.1:3306/score?characterEncoding=utf8&useSSL=false");
        ((MysqlDataSource) dataSource).setUser("root");
        ((MysqlDataSource) dataSource).setPassword("123456");
        //2.建立和服务器客户端之间的联系,连接好之后才能进行后续的 请求-响应 交互
        Connection connection = dataSource.getConnection();
        //3.构造sql
        String sql = "insert into exam_result values('hhh',88.0,88.0,88.1)";
        PreparedStatement statement = connection.prepareStatement(sql);
        //4.把sql发给服务器，返回一个整数，表示影响到的行数
        int n = statement.executeUpdate();
        System.out.println(n);
        //5.释放资源，关闭连接，释放顺序，后获取的先释放
        statement.close();
        connection.close();

    }
}
